﻿using Coldairarrow.Business.Base_Manage;
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.Interface;
using Coldairarrow.Util;
using EFCore.Sharding;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_Manage
{
    [Route("/OpenApi/[controller]/[action]")]
    [AllowAnonymous]
    public class AccountController : BaseApiController
    {

        OL_AccountBusiness oL_AccountBusiness { get; }
        public AccountController(IDbAccessor db)
        {
            oL_AccountBusiness = new OL_AccountBusiness(db);
        }
        [HttpPost]
        public async Task<string> PurAccounts(AccountDTO accountDTO)
        {
            await oL_AccountBusiness.PurAccounts(accountDTO);
            return "OK";
        }
        [HttpPost]
        public async Task<string> TransferAccounts(AccountDTO accountDTO)
        {
            await oL_AccountBusiness.TransferAccounts(accountDTO);
            return "OK";
        }

        [HttpPost]
        public async Task<Account> GetAccounts(AccountDTO accountDTO)
        {
            if (!accountDTO.AccountNO.IsNullOrEmpty()) return await oL_AccountBusiness.GetAccount(accountDTO.AccountNO);
            else return new Account() { Name = "查询无结果" };
        }
        [HttpPost]
        public async Task<List<AccountType>> GetAccountType(AccountDTO accountDTO)
        {
            if (!accountDTO.AccountType.IsNullOrEmpty()) return await oL_AccountBusiness.GetAccountType(accountDTO.AccountType);
            else return null;
        }
    }
}